package com.laxcen.controller2;

import com.github.pagehelper.PageInfo;
import com.laxcen.smoke.config.MyLog;
import com.laxcen.smoke.dto.req.*;
import com.laxcen.smoke.dto.res.SmartBoardDetailRes;
import com.laxcen.smoke.dto.res.SmartDetailRes;
import com.laxcen.smoke.dto.res.SmartRes;
import com.laxcen.smoke.entity.Smart;
import com.laxcen.smoke.entity.SmartBoard;
import com.laxcen.smoke.service.IntelligentMonitorService;
import com.laxcen.smoke.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "智能柜监控")
@RestController
@RequestMapping("/box")
public class IntelligentMonitorController {

    @Autowired
    private IntelligentMonitorService intelligentMonitorService;

    @ApiOperation(value = "添加智能柜",notes =
            "请求信息： \n" +
                    "&emsp; no &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; devicename &nbsp; : &nbsp; 智能柜名称 \n" +
                    "&emsp; address &nbsp; : &nbsp; 地址 \n" +
                    "&emsp; lng &nbsp; : &nbsp; 经度  \n" +
                    "&emsp; lat &nbsp; : &nbsp; 纬度 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/insert")
    @MyLog(operation = "添加智能柜")
    @RequiresPermissions("box:insert")
    public Response<Smart> insert(@RequestBody BoxInsertReq boxInsertReq){
        return intelligentMonitorService.insert(boxInsertReq.getNo(),boxInsertReq.getDevicename(),boxInsertReq.getLat(),boxInsertReq.getLng(),boxInsertReq.getAddress(),boxInsertReq.getRemark());
    }

    @ApiOperation(value = "修改智能柜",notes =
            "请求信息： \n" +
                    "&emsp; no &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; devicename &nbsp; : &nbsp; 智能柜名称 \n" +
                    "&emsp; address &nbsp; : &nbsp; 地址 \n" +
                    "&emsp; lng &nbsp; : &nbsp; 经度  \n" +
                    "&emsp; lat &nbsp; : &nbsp; 纬度 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/update")
    @MyLog(operation = "修改智能柜")
    @RequiresPermissions("box:update")
    public Response<Smart> update(@RequestBody BoxUpdateBox boxUpdateBox){
        return intelligentMonitorService.update(boxUpdateBox.getId(),boxUpdateBox.getNo(),boxUpdateBox.getDevicename(),boxUpdateBox.getLat(),boxUpdateBox.getLng(),boxUpdateBox.getAddress(),boxUpdateBox.getRemark());
    }

    @ApiOperation(value = "查询智能柜(导航栏)",notes =
            "请求信息： \n" +
                    "&emsp; searchtext &nbsp; : &nbsp; 搜索内容(设备名称、设备编号、地址) \n" +
                    "&emsp; roleflag &nbsp; : &nbsp; 用户权限标志(0超级管理员 1普通管理员) \n" +
                    "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
                    "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
                    "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
                    "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id  \n" +
                    "&emsp; no &nbsp; : &nbsp; 实体柜编号  \n" +
                    "&emsp; lat &nbsp; : &nbsp; 纬度  \n" +
                    "&emsp; lng &nbsp; : &nbsp; 经度  \n" +
                    "&emsp; address &nbsp; : &nbsp; 地址  \n" +
                    "&emsp; status &nbsp; : &nbsp; 状态码(0正常 1异常)  \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间  \n" +
                    "&emsp; upsstatus &nbsp; : &nbsp; ups状态(1正常 2电池 3异常)正常为绿色，电池和异常都为红色  \n" +
                    "&emsp; upselectricity &nbsp; : &nbsp; ups电量  \n" +
                    "&emsp;&emsp; versionno &nbsp; : &nbsp; 当前设备版本号 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注  \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/get")
    @RequiresPermissions("box:get")
    public Response<PageInfo<SmartRes>> get(@RequestBody BoxSelectTabReq boxSelectTabReq) {
        if (boxSelectTabReq.getPageNo()==null){
            boxSelectTabReq.setPageNo(1);
        }
        if (boxSelectTabReq.getPageSize()==null){
            boxSelectTabReq.setPageSize(10);
        }
        if (boxSelectTabReq.getPageNo()==null&&boxSelectTabReq.getPageSize()==null){
            boxSelectTabReq.setPageNo(1);
            boxSelectTabReq.setPageSize(10);
        }
        return intelligentMonitorService.getByTabList(boxSelectTabReq.getSearchtext(),boxSelectTabReq.getRoleflag(),boxSelectTabReq.getProvince(),boxSelectTabReq.getCity(),boxSelectTabReq.getArea(),boxSelectTabReq.getPageNo(),boxSelectTabReq.getPageSize());
    }

    @ApiOperation(value = "获取所有智能柜列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
                    "&emsp; roleflag &nbsp; : &nbsp; 用户权限标志(0超级管理员 1普通管理员) \n" +
                    "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
                    "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
                    "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
                    "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id  \n" +
                    "&emsp; no &nbsp; : &nbsp; 智能柜编号  \n" +
                    "&emsp; lat &nbsp; : &nbsp; 纬度  \n" +
                    "&emsp; lng &nbsp; : &nbsp; 经度  \n" +
                    "&emsp; address &nbsp; : &nbsp; 地址  \n" +
                    "&emsp; status &nbsp; : &nbsp; 状态码(0正常 1异常)  \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间  \n" +
                    "&emsp; upsstatus &nbsp; : &nbsp; ups状态(1正常 2电池 3异常) 正常为绿色，电池和异常都为红色 \n" +
                    "&emsp; upselectricity &nbsp; : &nbsp; ups电量  \n" +
                    "&emsp;&emsp; versionno &nbsp; : &nbsp; 当前设备版本号 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注  \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getalllist")
    @RequiresPermissions("box:getalllist")
    public Response<PageInfo<SmartRes>> getAllList(@RequestBody RoleFlagPageReq roleFlagPageReq)  {
        if (roleFlagPageReq.getPageNo()==null){
            roleFlagPageReq.setPageNo(1);
        }
        if (roleFlagPageReq.getPageSize()==null){
            roleFlagPageReq.setPageSize(10);
        }
        if (roleFlagPageReq.getPageNo()==null&&roleFlagPageReq.getPageSize()==null){
            roleFlagPageReq.setPageNo(1);
            roleFlagPageReq.setPageSize(10);
        }
        return intelligentMonitorService.getAllList(roleFlagPageReq.getPageNo(),roleFlagPageReq.getPageSize(),roleFlagPageReq.getRoleflag(),roleFlagPageReq.getProvince(),roleFlagPageReq.getCity(),roleFlagPageReq.getArea());
    }

    @ApiOperation(value = "查询智能柜详情",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 智能柜id \n" +
                    "返回信息： \n\n" +
                    "&emsp; airesult &nbsp; : &nbsp; 智能柜信息 \n" +
                    "&emsp;&emsp; id &nbsp; : &nbsp; 智能柜id \n" +
                    "&emsp;&emsp; no &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp;&emsp; lat &nbsp; : &nbsp; 纬度 \n" +
                    "&emsp;&emsp; lng &nbsp; : &nbsp; 经度 \n" +
                    "&emsp;&emsp; address &nbsp; : &nbsp; 地址 \n" +
                    "&emsp;&emsp; status &nbsp; : &nbsp; 状态码(0正常 1异常) \n" +
                    "&emsp;&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp;&emsp; upsstatus &nbsp; : &nbsp; ups状态(1正常 2电池 3异常) 正常为绿色，电池和异常都为红色 \n" +
                    "&emsp;&emsp; upselectricity &nbsp; : &nbsp; ups电量 \n" +
                    "&emsp;&emsp; versionno &nbsp; : &nbsp; 当前设备版本号 \n" +
                    "&emsp;&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; realresult &nbsp; : &nbsp; 实体柜信息 \n" +
                    "&emsp;&emsp; id &nbsp; : &nbsp; 实体柜id \n" +
                    "&emsp;&emsp; no &nbsp; : &nbsp; 实体柜编号 \n" +
                    "&emsp;&emsp; status &nbsp; : &nbsp; 状态码(0正常 1有异常 2故障中 3维护中 4不可用) \n" +
                    "&emsp;&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp;&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getdetail")
    @RequiresPermissions("box:getdetail")
    public Response<List<SmartDetailRes>> getdetail(@RequestBody CommonOneIdReq commonOneIdReq) {

        return intelligentMonitorService.getByOneList(commonOneIdReq.getId());
    }

    @ApiOperation(value = "查询实体柜详情",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 实体柜id \n" +
                    "返回信息： \n\n" +
                    "&emsp; list &nbsp; : &nbsp; 实体柜信息 \n" +
                    "&emsp;&emsp; id &nbsp; : &nbsp; 实体柜id \n" +
                    "&emsp;&emsp; no &nbsp; : &nbsp; 实体柜编号 \n" +
                    "&emsp;&emsp; lat &nbsp; : &nbsp; 纬度 \n" +
                    "&emsp;&emsp; lng &nbsp; : &nbsp; 经度 \n" +
                    "&emsp;&emsp; address &nbsp; : &nbsp; 地址 \n" +
                    "&emsp;&emsp; status &nbsp; : &nbsp; 状态码(0正常 1异常) \n" +
                    "&emsp;&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp;&emsp; upsstatus &nbsp; : &nbsp; ups状态(1正常 2电池 3异常)  正常为绿色，电池和异常都为红色 \n" +
                    "&emsp;&emsp; upselectricity &nbsp; : &nbsp; ups电量 \n" +
                    "&emsp;&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "&emsp; boxresult &nbsp; : &nbsp; 格子信息 \n" +
                    "&emsp;&emsp; id &nbsp; : &nbsp; 格子id \n" +
                    "&emsp;&emsp; boxonlyno &nbsp; : &nbsp; 格子编号 \n" +
                    "&emsp;&emsp; status &nbsp; : &nbsp; 状态码(0正常 1有异常 2故障中 3维护中 4不可用) \n" +
                    "&emsp;&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "&emsp;&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getdetailboard")
    @RequiresPermissions("box:getdetailboard")
    public Response<List<SmartBoardDetailRes>> getdetailBoard(@RequestBody CommonOneIdReq commonOneIdReq) {

        return intelligentMonitorService.getBoardByOneList(commonOneIdReq.getId());
    }


    @ApiOperation(value = "删除某一个智能柜",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 智能柜id \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/delete")
    @MyLog(operation = "删除智能柜")
    public Response delete(@RequestBody CommonOneIdReq commonOneIdReq){

        return intelligentMonitorService.delete(commonOneIdReq.getId());
    }

    @ApiOperation(value = "删除某一个实体柜",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 实体柜id \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/deleteboard")
    @MyLog(operation = "删除实体柜")
    public Response deleteBoard(@RequestBody CommonOneIdReq commonOneIdReq){

        return intelligentMonitorService.deleteBoard(commonOneIdReq.getId());
    }

    @ApiOperation(value = "添加格子",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 实体柜id \n" +
                    "&emsp; number &nbsp; : &nbsp; 格子数 \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/addbox")
    @MyLog(operation = "添加格子")
    public Response addbox(@RequestBody BoxInsertBoxReq boxInsertBoxReq){

        return intelligentMonitorService.addbox(boxInsertBoxReq.getId(),boxInsertBoxReq.getNumber(),boxInsertBoxReq.getRemark());
    }

//    @ApiOperation(value = "删除某一个格子",notes =
//            "请求信息： \n" +
//                    "&emsp; id &nbsp; : &nbsp; 格子id \n" +
//                    "返回码： \n" +
//                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
//                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
//    @PostMapping(value = "/deletebox")
//    @MyLog(operation = "删除格子")
//    public Response deleteBox(@RequestBody CommonOneIdReq commonOneIdReq){
//
//        return intelligentMonitorService.deletebox(commonOneIdReq.getId());
//    }

    @ApiOperation(value = "添加实体柜",notes =
            "请求信息： \n" +
                    "&emsp; smartid &nbsp; : &nbsp; 智能柜id \n" +
                    "&emsp; boardno &nbsp; : &nbsp; 实体柜编号 \n" +
                    "&emsp; specification &nbsp; : &nbsp; 主副柜标志 0主 1副  \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 1200 &nbsp; : &nbsp; 副柜编号已存在，请重新输入!  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/addreal")
    @MyLog(operation = "添加实体柜")
    public Response<SmartBoard> addReal(@RequestBody AddBoardReq addBoardReq){
        return intelligentMonitorService.addReal(addBoardReq.getSmartid(),addBoardReq.getBoardno(),addBoardReq.getSpecification(),addBoardReq.getRemark());
    }

    @ApiOperation(value = "编辑实体柜",notes =
            "请求信息： \n" +
                    "&emsp; boardid &nbsp; : &nbsp; 实体柜id \n" +
                    "&emsp; boardno &nbsp; : &nbsp; 实体柜编号 \n" +
                    "&emsp; specification &nbsp; : &nbsp; 主副柜标志 0主 1副  \n" +
                    "&emsp; remark &nbsp; : &nbsp; 备注 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 1200 &nbsp; : &nbsp; 副柜编号已存在，请重新输入!  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/updatereal")
    @MyLog(operation = "修改实体柜")
    public Response updateReal(@RequestBody UpdateBoardReq addBoardReq){

        return intelligentMonitorService.updateReal(addBoardReq.getBoardid(),addBoardReq.getBoardno(),addBoardReq.getSpecification(),addBoardReq.getRemark());
    }

//    @ApiOperation(value = "修改指定格子的状态",notes =
//            "请求信息： \n" +
//                    "&emsp; status &nbsp; : &nbsp; 格子状态 1正常 2占用 3异常 \n" +
//                    "&emsp; boxonlyno &nbsp; : &nbsp; 格子唯一编号 \n" +
//                    "返回码： \n" +
//                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
//                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
//    @PostMapping(value = "/updatebox")
//    @MyLog(operation = "修改格子状态")
//    public Response updateBox(@RequestBody UpdateBoxStatusReq updateBoxStatusReq){
//
//        return intelligentMonitorService.updateBox(updateBoxStatusReq.getStatus(),updateBoxStatusReq.getBoxonlyno());
//    }



}
